//
//  BasicViewController.m
//  GongFuYaYi
//
//  Created by 马卿 on 15/12/23.
//  Copyright © 2015年 马卿. All rights reserved.
//

#import "BasicViewController.h"
#import "UITableView+SDAutoTableViewCellHeight.h"

@interface BasicViewController ()

@end

@implementation BasicViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19],NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    self.navigationController.navigationBar.translucent = NO;
    
    [self.navigationController.navigationBar setBarTintColor:COLOR];
    
    
}
#pragma mark -修改导航栏的字体大小和颜色
- (void)chageTitleNameWithName:(NSString *)name{
    
    UILabel *labelNav = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
    labelNav.textColor = [UIColor whiteColor];
    labelNav.text = name;
    
    if (Screen_Width==414) {
        labelNav.font = [UIFont boldSystemFontOfSize:20.0];
    }else if (Screen_Width==375) {
        labelNav.font = [UIFont boldSystemFontOfSize:19.0];
    }else {
        labelNav.font = [UIFont boldSystemFontOfSize:18.0];
    }

    labelNav.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = labelNav;
}
- (void)createNaviBarButton {
    
    UIButton *but = [UIButton buttonWithType:UIButtonTypeCustom];
    but.frame = CGRectMake(0, 0, 45, 45);
    
    [but setImage:[UIImage imageNamed:@"accept_arrow"] forState:UIControlStateNormal];

    [but setImage:[UIImage imageNamed:@"accept_arrow"] forState:UIControlStateHighlighted];
    
    [but setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 28)];
    
    [but addTarget:self action:@selector(leftButtonClick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:but];
    
    self.navigationItem.leftBarButtonItem = leftItem;
    
}
#pragma mark - 返回
- (void)leftButtonClick{
    
    if (!self.presentEnter) {
        
        [self.navigationController popViewControllerAnimated:YES];
        
    }else{
        
        [self dismissViewControllerAnimated:1 completion:^{
            
        }];
    }
    
}
- (void)leftNavButtonClick {
    
    if (!self.presentEnter) {
        
        [self.navigationController popViewControllerAnimated:YES];
        
    }else{
        
        [self dismissViewControllerAnimated:1 completion:^{
            
        }];
    }
}

#pragma mark - 创建图片
- (UIImageView *)createImageViewFrame:(CGRect)frame imageName:(NSString *)imageName color:(UIColor *)color {
    UIImageView *imageView=[[UIImageView alloc]initWithFrame:frame];
    if (imageName)
    {
        imageView.image=[UIImage imageNamed:imageName];
    }
    if (color)
    {
        imageView.backgroundColor=color;
    }
    return imageView;
}

- (UITextField *)createTextFieldfFrame:(CGRect)frame font:(UIFont *)font placeholder:(NSString *)placeholder {
    UITextField *textField=[[UITextField alloc]initWithFrame:frame];
    textField.font=font;
    textField.textColor=[UIColor grayColor];
    textField.borderStyle=UITextBorderStyleNone;
    textField.placeholder=placeholder;
    return textField;
}


- (UIButton *)createButtonFrame:(CGRect)frame backImageName:(NSString *)imageName title:(NSString *)title titleColor:(UIColor *)color font:(UIFont *)font target:(id)target action:(SEL)action  {
    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame=frame;
    if (imageName)
    {
        [btn setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    }
    if (font)
    {
        btn.titleLabel.font=font;
    }
    if (title)
    {
        [btn setTitle:title forState:UIControlStateNormal];
    }
    if (color)
    {
        [btn setTitleColor:color forState:UIControlStateNormal];
    }
    if (target&&action)
    {
        [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    }
    return btn;
}

@end
